package com.hsnn.medstgmini.pro.base.controller;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.hsnn.medstgmini.Constants;
import com.hsnn.medstgmini.base.dict.service.DicAreaManager;
import com.hsnn.medstgmini.base.std.model.StdCompinfo;
import com.hsnn.medstgmini.pro.base.service.BaseDelrelationManager;
import com.hsnn.medstgmini.pro.base.service.BaseGoodsManager;
import com.hsnn.medstgmini.sys.model.SysUser;
import com.hsnn.medstgmini.util.Pagination;
/**
 * 
 *@category 配送关系管理
 *@author 邱磊
 *@date 2015年6月18日 上午9:55:57
 */
@Controller
@RequestMapping("/baseDelByPs")
public class BaseDelrelationByPsController {
	private static final Logger log = Logger.getLogger(BaseDelrelationByPsController.class);
	@Autowired
	private BaseDelrelationManager baseDelrelationManager;
	@Autowired
	private  HttpServletRequest request;
	@Autowired
	private BaseGoodsManager baseGoodsManager;
	@Autowired
	private DicAreaManager dicAreaManager;
	@Autowired
	private HttpSession session;
	
	@Value("#{sysProp['system.province']}")
    private String sysProvince;

	
	
	
	
	/**
	 * 
	 *@category 去地区页面(配送企业)
	 *@author 应晓川
	 *@date 2015年11月20日14:36:04
	 *@param 
	 *@return String
	 */
	@RequestMapping("/toSelectDelAreaByPs")
	public String toSelectDelAreaByPs(){
		List<Map<String, Object>> list = dicAreaManager.getAreaByFatherId(sysProvince);
		request.setAttribute("list", list);
		return "/pro/base/selectDelAreaByPs";
	}
	
	/**
	 *@category 获取未申报过的地区列表(配送企业)
	 *@author 应晓川
	 *@date 2015年11月20日14:50:30
	 *@param 
	 *@return Pagination
	 */
	@RequestMapping("/getSelectDelAreaByPs")
	@ResponseBody
	public Pagination getSelectDelArea(){
		log.info("获取未申报过的地区列表(配送企业)");
		Pagination page = new Pagination();
		SysUser user=(SysUser) request.getSession().getAttribute(Constants.USERINFO);
		StdCompinfo sc = (StdCompinfo)user.getInfo();
		String compCode = "";
		if(null!=sc){
			compCode = sc.getCompCode();
		}
		page.getConditions().put("compCode", compCode);
		page.getConditions().put("areaName", request.getParameter("areaName"));
		page.getConditions().put("fatherId", request.getParameter("fatherId"));
		return dicAreaManager.getMyProvinceAreaByPs(page);
	}
	/**
	 *@category 批量申报地区(配送企业)
	 *@author 应晓川
	 *@date 2015年11月20日15:19:00
	 *@param 
	 *@return Pagination
	 */
	@RequestMapping("/batchDeclare")
	@ResponseBody
	public Pagination batchDeclare(String param){
		log.info("批量申报地区(配送企业)"+param);
		Pagination page = new Pagination();
		SysUser user=(SysUser) request.getSession().getAttribute(Constants.USERINFO);
		try {
			StdCompinfo sc = (StdCompinfo)user.getInfo();
			if(null!=sc){
				page.setForm(sc);
			}
			page.getConditions().put("userId", user.getId());
			page.getConditions().put("param", param);
			baseDelrelationManager.batchDeclare(page);
			page.setSuccess(true);
		} catch (Exception e) {
			page.setSuccess(false);
			page.setMsg("申报失败！");
		}
		return  page;
	}
	
	
	/**
	 * 
	 *@category 去遴选结果查看(配送企业)
	 *@author 应晓川
	 *@date 2015年11月20日16:50:52
	 *@param 
	 *@return String
	 */
	@RequestMapping("/toDelRangeResultByPs")
	public String toDelRangeResultByPs(){
		return "/pro/base/delRangeResultByPs";
	}
	
	
	/**
	 *@category 获取遴选结果列表(配送企业)
	 *@author 应晓川
	 *@date 2015年11月20日17:00:02
	 *@param 
	 *@return Pagination
	 */
	@RequestMapping("/getDelRangeResultByPs")
	@ResponseBody
	public Pagination getDelRangeResultByPs(String areaName){
		log.info("获取遴选结果列表(配送企业)"+areaName);
		Pagination page = new Pagination();
		SysUser user=(SysUser) request.getSession().getAttribute(Constants.USERINFO);
		StdCompinfo sc = (StdCompinfo)user.getInfo();
		String compCode = "";
		if(null!=sc){
			compCode = sc.getCompCode();
		}
		page.getConditions().put("compCode", compCode);
		if( StringUtils.isNotBlank(areaName)){
			page.getConditions().put("areaName", areaName);
		}
		return baseDelrelationManager.getDelRangeResultByPs(page);
	}
	
	
}
